export class DataService {
  getItems(key: string = ''): any[] {
    if (!key || key === '') {
      return this.data.psapppvparts;
    }
    const items = this.loopFindItems(key, this.data.psapppvparts);
    return items || [];
  }

  loopFindItems(key: string, items: any[]): any[] | null {
    let arr: any[] | null = null;
    items.find(item => {
      if (item.psapppvpartid === key) {
        arr = item.psapppvparts;
        return true;
      } else {
        if (item.psapppvparts) {
          const result = this.loopFindItems(key, item.psapppvparts);
          if (result) {
            arr = result;
            return true;
          }
        }
      }
    });
    return arr;
  }

  // 面板测试数据
  data = {
    psapppvparts: [
      {
        psapppvparts: [
          {
            psapppvparts: null,
            psappportalviewname: 'AppPortalView',
            updateman: 'test_0805_001',
            pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
            createdate: '2022-02-17 14:40:01',
            pssysportletname: '未关闭的项目',
            portlettype: 'VIEW',
            colspan: 1,
            ordervalue: 100,
            ppsapppvpartid: '0873C268-6A1F-4C50-8A09-816A8C7CE20E',
            createman: 'test_0805_001',
            updatedate: '2022-02-17 14:40:01',
            validflag: 1,
            psapppvpartname: 'sysportlet1',
            ppsapppvpartname: 'container1',
            psapppvpartid: '275E09CE-6011-43DA-978A-9C8D56D8FA02',
            colid: 0,
            pvparttype: 'SYSPORTLET',
            psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
            pssysportletid: '051b5f92fb5357f7a27b423ca709e65d',
          },
        ],
        psappportalviewname: 'AppPortalView',
        updateman: 'test_0805_001',
        pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
        createdate: '2022-02-17 14:40:01',
        colspan: 1,
        ordervalue: 100,
        createman: 'test_0805_001',
        updatedate: '2022-02-17 14:40:01',
        validflag: 1,
        psapppvpartname: 'container1',
        psapppvpartid: '0873C268-6A1F-4C50-8A09-816A8C7CE20E',
        colid: 0,
        pvparttype: 'CONTAINER',
        psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
      },
      {
        psapppvparts: [
          {
            psapppvparts: [
              {
                psapppvparts: null,
                psappmenuname: 'Main',
                psappportalviewname: 'AppPortalView',
                updateman: 'test_0805_001',
                psappmenuid: 'e9961522de7c3fb96c9e53f76b3eba6e',
                pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
                createdate: '2022-02-17 14:40:02',
                title: '首页菜单',
                colspan: 1,
                ordervalue: 100,
                ppsapppvpartid: '23FA172A-7AA8-4369-B0B7-23322DE7C927',
                createman: 'test_0805_001',
                updatedate: '2022-02-17 14:40:02',
                validflag: 1,
                psapppvpartname: 'appmenu1',
                ppsapppvpartname: 'container3',
                psapppvpartid: '41C53492-2FBC-44A3-AAA3-33893A99B8A9',
                colid: 0,
                pvparttype: 'APPMENU',
                psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
              },
            ],
            psappportalviewname: 'AppPortalView',
            updateman: 'test_0805_001',
            col_lg: 6,
            col_xs: 6,
            pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
            col_sm: 6,
            col_md: 6,
            createdate: '2022-02-17 14:40:02',
            colspan: 1,
            ordervalue: 100,
            ppsapppvpartid: '9D5C6D0F-5932-445B-9A91-116D94814AD3',
            createman: 'test_0805_001',
            updatedate: '2022-02-17 14:40:02',
            validflag: 1,
            psapppvpartname: 'container3',
            ppsapppvpartname: 'container2',
            psapppvpartid: '23FA172A-7AA8-4369-B0B7-23322DE7C927',
            colid: 0,
            pvparttype: 'CONTAINER',
            psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
          },
          {
            psapppvparts: [
              {
                psapppvparts: null,
                psappportalviewname: 'AppPortalView',
                updateman: 'test_0805_001',
                pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
                createdate: '2022-02-17 14:40:02',
                colspan: 1,
                ordervalue: 100,
                ppsapppvpartid: 'AD187E34-FBAC-4E18-9689-F2AA9AF14108',
                createman: 'test_0805_001',
                updatedate: '2022-02-17 14:40:02',
                validflag: 1,
                psapppvpartname: 'appview1',
                ppsapppvpartname: 'container4',
                psapppvpartid: '39352D4A-501C-4FCB-95F1-2E1181833C36',
                colid: 0,
                pvparttype: 'APPVIEW',
                psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
              },
            ],
            psappportalviewname: 'AppPortalView',
            updateman: 'test_0805_001',
            col_lg: 6,
            col_xs: 6,
            pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
            col_sm: 6,
            col_md: 6,
            createdate: '2022-02-17 14:40:02',
            colspan: 1,
            ordervalue: 110,
            ppsapppvpartid: '9D5C6D0F-5932-445B-9A91-116D94814AD3',
            createman: 'test_0805_001',
            updatedate: '2022-02-17 14:40:02',
            validflag: 1,
            psapppvpartname: 'container4',
            ppsapppvpartname: 'container2',
            psapppvpartid: 'AD187E34-FBAC-4E18-9689-F2AA9AF14108',
            colid: 0,
            pvparttype: 'CONTAINER',
            psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
          },
          {
            psapppvparts: [
              {
                psapppvparts: null,
                psappportalviewname: 'AppPortalView',
                updateman: 'test_0805_001',
                pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
                createdate: '2022-02-17 14:40:02',
                title: '直接内容',
                contenttype: 'RAW',
                colspan: 1,
                ordervalue: 100,
                ppsapppvpartid: '9A8585B0-3A2A-4778-B2B2-0BB8A2F54445',
                createman: 'test_0805_001',
                rawcontent: '直接内容',
                updatedate: '2022-02-17 14:40:02',
                validflag: 1,
                psapppvpartname: 'rawitem1',
                ppsapppvpartname: 'container5',
                psapppvpartid: '8359AD82-619F-4716-9EE2-5F0C05B0EB97',
                colid: 0,
                pvparttype: 'RAWITEM',
                psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
              },
            ],
            psappportalviewname: 'AppPortalView',
            updateman: 'test_0805_001',
            col_lg: 6,
            col_xs: 6,
            pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
            col_sm: 6,
            col_md: 6,
            createdate: '2022-02-17 14:40:02',
            colspan: 1,
            ordervalue: 120,
            ppsapppvpartid: '9D5C6D0F-5932-445B-9A91-116D94814AD3',
            createman: 'test_0805_001',
            updatedate: '2022-02-17 14:40:02',
            validflag: 1,
            psapppvpartname: 'container5',
            ppsapppvpartname: 'container2',
            psapppvpartid: '9A8585B0-3A2A-4778-B2B2-0BB8A2F54445',
            colid: 0,
            pvparttype: 'CONTAINER',
            psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
          },
          {
            psapppvparts: [
              {
                psapppvparts: null,
                psappportalviewname: 'AppPortalView',
                updateman: 'test_0805_001',
                pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
                createdate: '2022-02-17 14:40:02',
                title: '直接内容',
                colspan: 1,
                ordervalue: 100,
                ppsapppvpartid: '6C807354-7BD8-46A9-8AB3-532A25877D3B',
                createman: 'test_0805_001',
                updatedate: '2022-02-17 14:40:02',
                validflag: 1,
                psapppvpartname: 'rawitem2',
                ppsapppvpartname: 'container6',
                psapppvpartid: '46EC345D-8861-48F0-B796-0FCA94BF2CF5',
                colid: 0,
                pvparttype: 'RAWITEM',
                psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
              },
            ],
            psappportalviewname: 'AppPortalView',
            updateman: 'test_0805_001',
            col_lg: 6,
            col_xs: 6,
            pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
            col_sm: 6,
            col_md: 6,
            createdate: '2022-02-17 14:40:02',
            colspan: 1,
            ordervalue: 130,
            ppsapppvpartid: '9D5C6D0F-5932-445B-9A91-116D94814AD3',
            createman: 'test_0805_001',
            updatedate: '2022-02-17 14:40:02',
            validflag: 1,
            psapppvpartname: 'container6',
            ppsapppvpartname: 'container2',
            psapppvpartid: '6C807354-7BD8-46A9-8AB3-532A25877D3B',
            colid: 0,
            pvparttype: 'CONTAINER',
            psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
          },
        ],
        psappportalviewname: 'AppPortalView',
        updateman: 'test_0805_001',
        layoutmode: 'TABLE_24COL',
        pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
        createdate: '2022-02-17 14:40:02',
        colspan: 1,
        ordervalue: 110,
        createman: 'test_0805_001',
        updatedate: '2022-02-17 14:40:02',
        validflag: 1,
        psapppvpartname: 'container2',
        psapppvpartid: '9D5C6D0F-5932-445B-9A91-116D94814AD3',
        colid: 0,
        pvparttype: 'CONTAINER',
        psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
      },
    ],
    psappportalviewname: 'AppPortalView',
    updateman: 'test_0805_001',
    psappviewname: 'AppPortalView',
    dynamodelflag: 0,
    layoutmode: 'TABLE_24COL',
    pssystemid: '2C40DFCD-0DF5-47BF-91A5-C45F810B0001',
    createdate: '2022-02-17 11:48:27',
    pssysappname: 'iBiz软件生产管理',
    title: '应用门户视图',
    colmodel: '50%;50%',
    psappmodulename: '未分类模块',
    psappmoduleid: 'b608adba61b9756cbfa444e27869dfb5',
    psappviewtype: 'APPPORTALVIEW',
    pspfid: 'VUE_R7',
    pssysappid: 'bc1f55f482a2df2bede07c661806c4eb',
    createman: 'test_0805_001',
    psappviewid: '3DEFA381-5219-4670-9300-BB191266044D',
    updatedate: '2022-02-17 14:40:01',
    modcolor: 'orange',
    psappportalviewid: '3DEFA381-5219-4670-9300-BB191266044D',
  };
}

export const data = new DataService();
